home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
spoc88.zip
/
SCRHND.ZIP
/
XSCRHND.PRO
< prev
next >
Wrap
Text File
|
1988-06-03
|
16KB
|
591 lines
/* Listing 3: XSCRHND.PRO */
/****************************************************************
Turbo Prolog Toolbox
(C) Copyright 1987 Borland International.
SCRHND
======
This module implements a screen handler called by:
scrhnd(TOPLINE,ENDKEY)
TOPLINE = on/off - determines if there should be a top line
ENDKEY - Esc or F10 used to return values
****************************************************************/
/***************************************************************
* Modified 2/5/88 G.Wood
* Added capabilities to:
* - enable all function keys and define an additional input key
* - allow the tab to wrap-around
* - correct cursor positioning when an input field is filled,
* including wrap-around
* - define a back tab function from the middle of an input field
*
* See clauses scr
* nextfield
* chk_found
* prevfield
***************************************************************/
/*
DOMAINS
FNAME=SYMBOL
TYPE = int(); str(); real()
DATABASE
/* Database declarations used in scrhnd */
insmode /* Global insertmode */
actfield(FNAME) /* Actual field */
screen(SYMBOL,DBASEDOM) /* Saving different screens */
value(FNAME,STRING) /* value of a field */
field(FNAME,TYPE,ROW,COL,LEN) /* Screen definition */
txtfield(ROW,COL,LEN,STRING)
windowsize(ROW,COL).
notopline
/* DATABASE PREDICATES USED BY VSCRHND */
windowstart(ROW,COL)
mycursord(ROW,COL)
/* Database declarations used in lineinp */
lineinpstate(STRING,COL)
*/
PREDICATES
/* SCREEN DRIVER */
scrhnd(SYMBOL,KEY)
endkey(KEY)
scr(KEY)
writescr
showcursor
mkheader
showoverwrite
ass_val(FNAME,STRING)
valid(FNAME,TYPE,STRING)
typeerror
chng_actfield(FNAME)
field_action(FNAME)
field_value(FNAME,STRING)
noinput(FNAME)
types(INTEGER,TYPE,STRING) /* Definition of the known types */
/*****************************************************************/
/* Create the window */
/* This can be used to create the window automatically from the */
/* windowsize predicate. */
/*****************************************************************/
PREDICATES
createwindow(SYMBOL)
CLAUSES
createwindow(off):-
windowsize(R,C),!,
R1=R+3, C1=C+3,
makewindow(81,23,66,"",0,0,R1,C1).
createwindow(on):-
windowsize(R,C),!,
R1=R+3, C1=C+3,
makewindow(85,112,0,"",0,0,1,C1),
makewindow(81,23,66,"",1,0,R1,C1).
/*****************************************************************/
/* Intermediate predicates */
/*****************************************************************/
PREDICATES
trunc_(LEN,STRING,STRING)
oldstr(FNAME,STRING)
settopline(SYMBOL)
CLAUSES
endkey(fkey(10)):-!.
endkey(esc).
/*************************************************************
* Modified 2/5/88 G.Wood
* Added clauses to endkey for fkeys 1 thru 9, and
* new symbolic key 'plus'. Allows these keys to terminate
* the screen handling predicate, scrhnd
*************************************************************/
endkey(fkey(1)):-!.
endkey(fkey(2)):-!.
endkey(fkey(3)):-!.
endkey(fkey(4)):-!.
endkey(fkey(5)):-!.
endkey(fkey(6)):-!.
endkey(fkey(7)):-!.
endkey(fkey(8)):-!.
endkey(fkey(9)):-!.
endkey(plus):-!.
trunc_(LEN,STR1,STR2):-str_len(STR1,L1),L1>LEN,!,
frontstr(LEN,STR1,STR2,_).
trunc_(_,STR,STR).
settopline(_):-retract(notopline),fail.
settopline(off):-!,assert(notopline).
settopline(_).
oldstr(FNAME,S):- value(FNAME,S),!.
oldstr(_,"").
ass_val(FNAME,_):- retract(value(FNAME,_)),fail.
ass_val(FNAME,VAL):-VAL><"",assert(value(FNAME,VAL)),fail.
ass_val(_,_).
chng_actfield(_):-typeerror,!,fail.
chng_actfield(_):-
retract(actfield(_)),fail.
chng_actfield(FNAME):-
assert(actfield(FNAME)).
typeerror:-
actfield(FNAME),
field(FNAME,TYPE,_,_,_),
value(FNAME,VAL),
not(valid(FNAME,TYPE,VAL)),
beep,!.
valid(_,str,_).
valid(_,int,STR):-str_int(STR,_).
valid(_,real,STR):-str_real(STR,_).
/* The known types */
types(1,int,"integer").
types(2,real,"real").
types(3,str,"string").
/******************************************************************/
/* SCREEN DRIVER */
/* Screen definition/input is repeated until F10 is pressed */
/******************************************************************/
scrhnd(STATUSON,KEY):-
settopline(STATUSON),
mkheader,
writescr,
field(FNAME,_,R,C,_),!,cursor(R,C),
chng_actfield(FNAME),
showcursor,
repeat,
writescr,
keypressed,/*Continuation until keypress means
that time dependent
user functions can be updated*/
readkey(KEY),
scr(KEY),
showcursor,
endkey(KEY),!.
/*****************************************************************/
/* Find the next field */
/*****************************************************************/
PREDICATES
/* The predicates should be called with:
ACTROW, ACTCOL, MAXROW, MAXCOL, NEWROW, NEWCOL */
best_right(ROW,COL,ROW,COL,ROW,COL)
best_left(ROW,COL,ROW,COL,ROW,COL)
best_down(ROW,COL,ROW,COL,LEN,ROW,COL)
best_up(ROW,COL,ROW,COL,LEN,ROW,COL)
better_right(ROW,COL,ROW,COL,ROW,COL)
better_left(ROW,COL,ROW,COL,ROW,COL)
better_field(ROW,COL,ROW,COL,LEN,ROW,COL,LEN)
calcdist(ROW,COL,ROW,COL,LEN,LEN)
move_left
move_right
nextfield(ROW,COL)
gtfield(ROW,ROW,COL,COL)
prevfield(ROW,COL)
/***************************************************
* Modified 2/5/88 G.Wood
* Added LEN to predicate chk_found. See changes to
* chk_found clause.
***************************************************/
/* chk_found(FNAME,ROW,COL,ROW,COL) */
chk_found(FNAME,ROW,COL,ROW,COL,LEN)
setlastfield
CLAUSES
best_right(R0,C0,R1,C1,ROW,COL):-
field(_,_,R2,C2,_), C2>C0,
better_right(R0,C0,R1,C1,R2,C2),!,
best_right(R0,C0,R2,C2,ROW,COL).
best_right(_,_,R,C,R,C).
better_right(R0,_,R1,_,R2,_):-abs(R2-R0)<abs(R1-R0),!.
better_right(R0,_,R1,C1,R2,C2):-abs(R2-R0)=abs(R1-R0),C2<C1.
best_left(R0,C0,R1,C1,ROW,COL):-
field(_,_,R2,C2,_), C2<C0,
better_left(R0,C0,R1,C1,R2,C2),!,
best_left(R0,C0,R2,C2,ROW,COL).
best_left(_,_,R,C,R,C).
better_left(R0,_,R1,_,R2,_):-abs(R2-R0)<abs(R1-R0),!.
better_left(R0,_,R1,C1,R2,C2):-abs(R2-R0)=abs(R1-R0),C2>C1.
best_down(R0,C0,R1,C1,L1,ROW,COL):-
field(_,_,R2,C2,L2), R2>R0,
better_field(R0,C0,R1,C1,L1,R2,C2,L2),!,
best_down(R0,C0,R2,C2,L2,ROW,COL).
best_down(_,_,R,C,_,R,C).
best_up(R0,C0,R1,C1,L1,ROW,COL):-
field(_,_,R2,C2,L2), R2<R0,
better_field(R0,C0,R1,C1,L1,R2,C2,L2),!,
best_up(R0,C0,R2,C2,L2,ROW,COL).
best_up(_,_,R,C,_,R,C).
better_field(R0,C0,R1,C1,L1,R2,C2,L2):-
calcdist(R0,C0,R1,C1,L1,DIST1),
calcdist(R0,C0,R2,C2,L2,DIST2),
DIST2<DIST1.
calcdist(R0,C0,R1,C1,L1,DIST):-
C11=C1+L1,
max(C0,C1,H1),
min(H1,C11,H2),
DIST=3*abs(R1-R0)+abs(H2-C0).
move_left:-
not(typeerror),
actfield(FNAME),
field(FNAME,_,R,C,_),!,
best_left(R,C,-100,-100,ROW,COL),
field(F1,_,ROW,COL,_),
chng_actfield(F1),!,
cursor(ROW,COL).
move_right:-
not(typeerror),
actfield(FNAME),
field(FNAME,_,R,C,_),!,
best_right(R,C,-100,-100,ROW,COL),
field(F1,_,ROW,COL,_),
chng_actfield(F1),!,
cursor(ROW,COL).
/*************************************************************
* Modified 2/5/88 G. Wood
* Changed chk_found clause in prevfield to include LEN.
* Changed existing chk_found clauses to incorporate the
* additional variable position.
* Added new chk_found clause (second position) to check
* if current cursor position is in a defined field
* These changes will allow use of back-tab when anywhere
* in a field to return to first character of field then
* proceed to "back up" one field at a